<template>
  <div class="goodsDetail">
    <div class="tableDetail">
      <el-scrollbar
        wrap-class="scrollbar-wrapper"
        wrap-style="overflow-x: auto;"
      >
        <el-table
          border
          :data="BaseStockData"
          height="380"
          :row-class-name="tableRowClassName"
          :row-key="getRowKey"
          style="width: 400px"
        >
          <el-table-column width="55">
            <template #default="{ row }">
              <el-radio-group v-model="BSID" @change="changeRadio">
                <el-radio :label="row.BSID" />
              </el-radio-group>
            </template>
          </el-table-column>
          <el-table-column :label="translate('基站编码')" prop="BSID" />
          <el-table-column :label="translate('基站名称')">
            <template #default="{ row }">
              <div>{{ '[' + row.BSID + ']' + row.BSName }}</div>
            </template>
          </el-table-column>
        </el-table>
      </el-scrollbar>
    </div>
    <div class="tableDetail">
      <el-scrollbar
        wrap-class="scrollbar-wrapper"
        wrap-style="overflow-x: auto;"
      >
        <el-table
          ref="multipleTable"
          border
          :data="tableData"
          :loading="loading"
          height="380"
          :row-class-name="tableRowClassName"
          :row-key="getRowKey"
          style="width: 400px"
          @selection-change="handleSelectionChange"
        >
         <el-table-column width="55">
            <template #default="{ row }">
              <el-checkbox v-model="row.checked" @change="changeList(row)"></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column :label="translate('序号')" type="index" width="60" />
          <el-table-column :label="translate('射频码')" prop="ESLCode" />
          <el-table-column :label="translate('ESL名称')" prop="ESLName" />
        </el-table>
      </el-scrollbar>
      <div v-if="total > 0" class="pagination">
        <ElPagination
          background
          :current-page="pageNo"
          :layout="layout"
          :page-size="pageSize"
          :total="total"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        />
      </div>
    </div>
  </div>
</template>
<script>
  import { ESLInfoData } from '@/api/eslstock'
  import { translate } from '@/i18n'
  export default {
    name: 'Detail',
    components: {},
    props: {
      form: {
        type: Object,
        default: () => {
          return {}
        },
      },
      basestockdata: {
        type: Array,
        default: () => {
          return []
        },
      },
      diolog: {
        type: Boolean,
        default: false,
      },

    },
    emits: ['selectlist'],
    data() {
      return {
        formInfo: this.form,
        tableData: [],
        BaseStockData: this.basestockdata,
        pageNo: 1,
        pageSize: 20,
        BSID: '',
        total: 0,
        translate: translate,
        SelectList: {},
        loading: false,
      }
    },
    watch: {
      diolog: {
        handler(val) {
          console.log(val)
          if (val) {
            this.BSID = ''
            this.getList()
          }
        },
        immediate: true,
      },
    },
    created() {
      if (this.BaseStockData && this.BaseStockData.length > 0) {
        // this.BSID = this.BaseStockData[0].BSID
        this.getList()
      }
    },
    methods: {
      //分页条数切换
      handleSizeChange(val) {
        this.pageSize = val
        this.getList()
      },
      //分页切换
      handleCurrentChange(val) {
        this.pageNo = val
          this.getList()

      },
      handleSelectionChange(e) {
        console.log(e)

      },
      changeList(row) {
        console.log(row)
        this.$emit('selectlist', this.SelectList)
      },
      async changeRadio(val) {
        this.loading = true
        this.BSID = val
        await this.getList()

      },
      async ESLInfolist() {
        const params = {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
          tableName: '',
          sort: '',
          order: '',
          wheres: JSON.stringify([
            {
              name: 'BSID',
              value:  this.BSID,
              displayType: 'like',
            },
          ]),
          export: false,
          value: '',
        }
        const data = await ESLInfoData(params)
        if(data.data.rows&&data.data.rows.length>0) {
          if(this.tableData.length>0){
            data.data.rows.map((item) =>{
              this.tableData.map((item1) =>{
                if(item.ID === item1.ID) {
                  item1.checked = true
                }
              })
            })
          }
        }else {
          this.tableData.map((item1) =>{
               item1.checked = false
              })
        }
           this.SelectList = {
                arrList1:this.tableData,
                Bisi: this.BSID
           }
           this.$emit('selectlist', this.SelectList)
        // this.tableData = data.data.rows
        // this.total = data.data.total
      },
      async getList() {
        const params = {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
          tableName: '',
          sort: '',
          order: '',
          wheres: JSON.stringify([
            {
              name: 'BSID',
              value: '',
              displayType: 'like',
            },
          ]),
          export: false,
          value: '',
        }
        const data = await ESLInfoData(params)
        this.tableData = data.data.rows
        this.total = data.data.total
        if(this.BSID) {
          this.ESLInfolist()
        }
        this.loading = true
        console.log(this.tableData)
      },
    },
  }
</script>
<style lang="scss" scoped>
  .goodsDetail {
    display: flex;
    min-height: 300px;
  }
  .flex_align {
    display: flex;
    align-items: center;
  }
  .tableDetail {
    padding: 10px;
    .button-add {
      text-align: end;
      padding: 10px;
    }
  }
  .main_active {
    display: inline-block;
    width: 120px;
    text-align: right;
  }
  .mr20 {
    margin-right: 20px;
  }

  .w400 {
    width: 400px !important;
  }
  .mt20 {
    margin-top: 10px;
  }
  .mr10 {
    margin-right: 10px;
  }
  .w320 {
    width: 320px;
  }
  ::v-deep .el-scrollbar__wrap {
    overflow-x: auto;
    height: calc(100% + 20px); //多出来的20px是横向滚动条默认的样式
  }
  ::v-deep .el-scrollbar .el-scrollbar__wrap .el-scrollbar__view {
    white-space: nowrap;
    display: inline-block;
  }
  ::v-deep .el-table--scrollable-x .el-table__body-wrapper {
    overflow-x: hidden;
  }
  ::v-deep input[type='number']::-webkit-inner-spin-button,
  ::v-deep input[type='number']::-webkit-outer-spin-button {
    -webkit-appearance: none !important;
    margin: 0 !important;
  }
  ::v-deep .el-pagination {
    margin: 0 !important;
  }
  ::v-deep .el-radio__label {
    display: none;
  }
</style>
